package com.haust.leyou.pojo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.validator.constraints.Length;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.Pattern;
import java.util.Date;

/**
 * @Auther: csp1999
 * @Date: 2020/12/17/21:07
 * @Description: 用户实体类
 */
@Table(name = "tb_user")
public class User {
    /**
     * 主键id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 用户名(4-30位)
     *
     * hibernate-validator注解：被注释的字符串的大小必须在指定的范围内
     * min：最小长度
     * max：最大长度
     * message：不符合条件时提示信息
     */
    @Length(min = 4,max = 30,message = "用户名必须在4-30位之间")
    private String username;

    /**
     * 密码
     */
    @JsonIgnore // 对象序列化为json 字符串时，忽略该属性，这样就可以不暴漏密码到前端
    @Length(min = 4,max = 12,message = "用户密码必须在4-12位之间")
    private String password;

    /**
     * 电话
     *
     * hibernate-validator注解：被注释的元素必须符合指定的正则表达式
     * regexp = "^1[356789]\\d{9}$" : 满足电话号码的格式
     */
    @Pattern(regexp = "^1[356789]\\d{9}$",message = "电话格式不合法")
    private String phone;

    /**
     * 创建时间
     */
    private Date created;

    /**
     * 密码的盐值
     */
    @JsonIgnore // 对象序列化为json 字符串时，忽略该属性，这样就可以不暴漏盐值到前端
    private String salt;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }
}
